package com.wn.class30.cotroller.houtai;


import com.wn.class30.service.BackProductService;
import com.wn.class30.tools.Page;
import com.wn.class30.tools.Result;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
public class BackProductController {

    @Resource
    private BackProductService backProductService;

    @RequestMapping("/houtai/page/products/product/getAllBusiness")
    public Result getAllBusiness(){
        return new Result("200","success",null,backProductService.getAllBusiness());
    }
    @RequestMapping("/houtai/page/products/product/getAllProTypes")
    public Result getAllProTypes(){
        return new Result("200","success",null,backProductService.getAllProTypes());
    }
    @RequestMapping("/houtai/page/products/product/list")
    @RequiresPermissions("/houtai/page/products/product/list")
    public Result getList(){
        return new Result("200","success",null,null);
    }
    @RequestMapping("/houtai/products/getProducts")
    public Result getProductsByPage(Integer page,Integer limit,String name, String proCode, String status,String businessName,String proType){
        Map<String,String> map = new HashMap<>();
        map.put("page",String.valueOf(page));
        map.put("limit",String.valueOf(limit) );
        map.put("name", name);
        map.put("proCode", proCode);
        map.put("status", status);
        map.put("businessName", businessName);
        map.put("proType", proType);
        Page pager = new Page();
        pager.setCurrentPage(page);
        pager.setPageSize(limit);
        int count = backProductService.selectCount((HashMap) map);
        pager.setTotalSize(count);
        pager.setTotalPage(count%limit==0?count/limit:count/limit+1);
        return new Result("0","success",pager, (List) backProductService.select((HashMap) map));
    }
}
